/**
 * 新增页面JS
 * User: zhaoming
 * Date: 15-8-17
 * Time: 下午5:58
 * To change this template use File | Settings | File Templates.
 */
$(function(){
    //激活左侧导航菜单
    activeNavBar("MANAGE_OPT_ORG_INFO");
    initSelect2();

    var param = [
        {
            id: 'provinceCode',
            url: springUrl+ '/web/orgInfo/listDistrictInfo',
            code: 'districtCode',
            name: 'districtName',
            parent: ''
        },{
            id: 'cityCode',
            url: springUrl+ '/web/orgInfo/listDistrictInfo',
            code: 'districtCode',
            name: 'districtName',
            parent: 'parentDistrictCode'
        },{
            id: 'countyCode',
            url: springUrl+ '/web/orgInfo/listDistrictInfo',
            code: 'districtCode',
            name: 'districtName',
            parent: 'parentDistrictCode'
        }
    ];
    new Linkage().init(param);
    
    $("#saveBtn").click(function(){
        save();
    });
    $("#goBackBtn, #headGoBackBtn").click(function(){
        window.forward(springUrl+ "/web/orgInfo/index");
    });
});

/**
 * 保存
 */
function save(){
    if($('#addForm').trigger("validate").isValid()){
        var index =  layer.msg('正在处理中...', {icon: 16, shade: 0.3, time: 0});
        jQuery.ajax({
            type: "POST",
            dataType: "json",
            url: springUrl + "/web/orgInfo/insert",
            data: {
                orgName: $('#orgName').val(),
                linkman: $('#linkman').val(),
                mobileNo: $('#mobileNo').val(),
                provinceCode: $('#provinceCode').val(),
                provinceName: $('#provinceCode').val()!="" ? $('#provinceCode option:selected').text() : "",
                cityCode: $('#cityCode').val(),
                cityName: $('#cityCode').val()!="" ? $('#cityCode option:selected').text() : "",
                countyCode: $('#countyCode').val(),
                countyName: $('#countyCode').val()!="" ? $('#countyCode option:selected').text() : "",
                address: $('#address').val(),
                remark: $('#remark').val(),
                isEnable: 1
            },
            success: function (data) {
                layer.close(index);
                Alert.success("数据保存成功!", function(){
                    window.forward(springUrl+ "/web/orgInfo/index");
                });
            },
            error: function(data){
                layer.close(index)
                Alert.error(data.responseText);
            }
        });
    }
}

